﻿(function ($) {
    app.modals.CreateOrEditModal = function () {
        //
        //var _$courseScheduleDataTable = $('DataTableSchedule');
        //------------------------
        var _courseService = abp.services.app.course;
        var _modalManager;
        var _$form = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;

            _$form = _modalManager.getModal().find('form[name=ObjectForm]');
            _$form.validate();
            initPage();
            
        };
        
        this.save = function () {
            if (!_$form.valid()) {
                return;
            }

            var domainObject = _$form.serializeFormToObject();

            _modalManager.setBusy(true);
            _courseService.createOrUpdateObject({
                course: domainObject
            }).done(function (result) {
                abp.notify.info(app.localize('SavedSuccessfully'));
                _modalManager.setResult(result);
                _modalManager.close();
                abp.event.trigger('app.CreateOrEditModalSaved', result);
            }).always(function () {
                _modalManager.setBusy(false);
            });
        };
    };
   

})(jQuery);

function initPage()
{
    //设置课程类型第一个选中
    //$("input[name='CourseType'][value=1]").attr("checked", "true");
    $("#ChargeTime").attr("disabled", "disabled");
    $("#ChargeTime").hide();
    $("#Times").hide();
    $("#lblText").hide();

    var _courseName = "";
    //年级
    $("#GradeGUID").change(function () {
        if ($("#IsAutoCreateName").is(":checked")) {
            //$("input[name='CourseName']").each(function () {
            //    _courseName += $(this).val() + ',';
            //})
            _courseName += $("#GradeGUID option:checked").text()
            $("#CourseName").val(_courseName);
        }
    })
    //科目
    $("#SubjectGUID").change(function () {
        if ($("#IsAutoCreateName").is(":checked")) {
            _courseName += $("#SubjectGUID option:checked").text()
            $("#CourseName").val(_courseName);
        }
    })
    //类型
    $("#SubjectTypeGUID").change(function () {
        if ($("#IsAutoCreateName").is(":checked")) {
            _courseName += $("#SubjectTypeGUID option:checked").text()
            $("#CourseName").val(_courseName);
        }
    })

    //计费方式切换
    $("#ChargeTypeList").change(function () {
        if ($("#ChargeTypeList").val() == "1") {
            $("#PriceUnits").html("元/小时");
            $("#Times").html("小时/期");
        }
        else if ($("#ChargeTypeList").val() == "2") {
            $("#PriceUnits").html("元/次");
            $("#Times").html("次/期");
        }
    })
    //按期收费
    $("#IsAnQi").change(function () {
        if ($("#IsAnQi").is(":checked")) {
            $("#ChargeTime").show();
            $("#Times").show();
            $("#lblText").show();
            $("#ChargeTime").removeAttr("disabled");
        }
        else {

            $("#ChargeTime").val(0);
            $("#ChargeTime").attr("disabled", "disabled");
            $("#ChargeTime").hide();
            $("#Times").hide();
            $("#lblText").hide();
        }
    })
}

function addRow()
{
    $("#btnAddRow").click(function () {
        var newRow = $("#trRow").clone();
        $("#addRow").before(newRow);
        alert("Ok");
    })
}
function d()
{
    
    
}